var $ = require('../../common/helper.js');
Page({
	data: {
		person: {}
	},
	onLoad: function (options) {
		$.overload(false);
		var person = $.storage('person'), placeholder = '';
		if (!person.address || person.address == '') {
			person.address = '请选择地址';
			placeholder = 'placeholder';
		}
		this.setData({
			person: person,
			placeholder: placeholder
		});
	},
	postForm: function (e) {
		var data = e.detail.value;
		$.post('api.php?app=member&act=edit_info', data, function (json) {
			if (json.error != 0) {
				$.overloadError(json.msg);
				return;
			}
			$.storage('person', json.data);
			$.overloadSuccess('修改成功');
			wx.navigateBack();
		});
	},
	getAddress: function () {
		var _this = this;
		wx.chooseAddress({
			success: function (res) {
				//userName:收货人姓名
				//telNumber:收货人手机号码
				//provinceName:国标收货地址第一级地址
				//cityName:国标收货地址第二级地址
				//countyName:国标收货地址第三级地址
				//detailInfo:详细收货地址信息
				//nationalCode:收货地址国家码
				//postalCode:邮编
				if (res.errMsg == 'chooseAddress:ok') {
					var person = _this.data.person;
					person.address = $.comboCity(res.provinceName, res.cityName, res.countyName, res.detailInfo);
					_this.setData({
						person: person,
						placeholder: ''
					});
				}
			}
		});
	}
})